/*
 *  Copyright (C) 2010 Fabien Renaud
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.boc.botv.dao.impl;

import com.boc.botv.common.Database;
import com.boc.botv.dao.BetInstanceDao;
import com.boc.botv.model.BetInstance;
import java.util.List;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Fabien Renaud
 */
@Repository("betInstanceDao")
public class BetInstanceDaoImpl implements BetInstanceDao {

  public void updateGame(BetInstance betInstance) {
    Database.getSession().update(betInstance);
  }

  public void saveGame(BetInstance betInstance) {
    Database.getSession().save(betInstance);
  }

  public void deleteGame(BetInstance betInstance) {
    Database.getSession().delete(betInstance);
  }

  public BetInstance getGame(int betInstanceId) {
    return (BetInstance) Database.getSession().load(BetInstance.class, betInstanceId);
  }

  public List<BetInstance> getGames() {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance").list();
  }

  public List<BetInstance> getGamesByStatus(int status) {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance as beti where beti.status=" + status).list();
  }

  public List<BetInstance> getGamesByChoice(int choiceId) {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance as beti where beti.choice=" + choiceId).list();
  }

  public List<BetInstance> getGamesByUser(int userId) {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance as beti where beti.user=" + userId).list();
  }

  public List<BetInstance> getGamesByUserAndStatus(int userId, int status) {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance as beti where beti.user=" + userId + " and beti.status=" + status).list();
  }

  public List<BetInstance> getGamesByBet(int betId) {
    return (List<BetInstance>) Database.getSession().createQuery("from BetInstance as beti where beti.bet=" + betId).list();
  }
}
